﻿using IBApi;
using IBRx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;

namespace SampleConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            IBRxClient client = new IBRxClient();
            IBRxClientRequest clientRequest = new IBRxClientRequest(client);

            clientRequest.eConnect("127.0.0.1", 4001, 0, false);

            var tickPrice = RxExtensions.WithCachedSnapshot(client.TickPrice,
                quote => quote.TickerId);
            tickPrice.Sample(TimeSpan.FromSeconds(1)).Timestamp().Subscribe(
                x => Console.WriteLine("OnNext: {0}, after {1} sec", x.Value.Price, x.Timestamp.Second),
                ex => Console.WriteLine("OnError: {0}", ex.Message),
                () => Console.WriteLine("OnCompleted"));

            Contract con = new Contract();
            con.Symbol = "EUR";
            con.Currency = "USD";
            con.Exchange = "IDEALPRO";
            con.SecType = "CASH";
            int tickerId = 100001;
            clientRequest.reqMktData(tickerId, con, "", false, null);

            Console.ReadLine();
            clientRequest.cancelMktData(tickerId);
        }


    }
}
